/*java jdk 1.7+
# -*- coding: utf-8 -
'''
Created on 2020年05月10日
@author: zxyong 13738196011
'''*/

package com.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import com.zxy.common.Com_Fun;
import com.zxy.common.Com_Para;
import com.zxy.db_Self.Db_Common_Self;

//演示h5地址
public class IN_A01_CCC888 implements com.zxy.common.ParamName_InterFace
{
	public StringBuilder	strResult		= new StringBuilder();
	public String			user_main_id			= null;
	public String			session_id		= null;
	public String			param_name		= null;
	public String			param_value1	= null;
	public String			param_value2	= null;
	public String			param_value3	= null;
	public String			param_value4	= null;
	public String			param_value5	= null;
	public String			param_value6	= null;
	public String			param_value7	= null;
	public String			param_value8	= null;
	public String			param_value9	= null;
	public String			param_value10	= null;
	private String			frame_name		= "";
	// 演示h5部署地址
	private String			DemoUrl			= "/data/usr/local/webapps/cdi_CenterData/";	//

	public void init_start()
	{
		this.frame_name = Get_app_frame();
		String strZipFile = ZipCodeFile();
		try
		{
			this.strResult.append("{\"" + param_name
					+ "\":[{\"s_result\":\"1\",\"error_desc\":\"\",\"biz_url\":\""
					+ strZipFile + "\",\"biz_name\":\"" + strZipFile + "\"}]}");
		}
		catch(Exception e)
		{
			Com_Fun.debug_in(e,this.toString());
		}
	}

	private String ZipCodeFile()
	{
		String strZipName = frame_name + "_" + Com_Fun.DateTimeStr("yyyy-MM-dd")
				+ ".zip";
		String strF = ZipFiles(DemoUrl + "//" + frame_name,DemoUrl + "//"
				+ strZipName);
		if(!strF.equals("-1"))
			return strZipName;
		else
			return "";
	}

	private String ZipFiles(String sourPath, String targetPathFile)
	{
		// 创建zip输出流
		ZipOutputStream out = null;
		File sourceFile = null;
		try
		{
			out = new ZipOutputStream(new FileOutputStream(targetPathFile));
			sourceFile = new File(sourPath);
			// 调用函数
			compress(out,sourceFile,sourceFile.getName());
			out.close();
		}
		catch(Exception e)
		{
			Com_Fun.debug_in(e,this.toString());
			targetPathFile = "";
		}
		return targetPathFile;
	}

	private void compress(ZipOutputStream out, File sourceFile, String base) throws Exception
	{
		// 如果路径为目录（文件夹）
		if(sourceFile.isDirectory())
		{
			// 取出文件夹中的文件（或子文件夹）
			File[] flist = sourceFile.listFiles();

			if(flist.length == 0)// 如果文件夹为空，则只需在目的地zip文件中写入一个目录进入点
			{
				out.putNextEntry(new ZipEntry(base + "/"));
			}else
			// 如果文件夹不为空，则递归调用compress，文件夹中的每一个文件（或文件夹）进行压缩
			{
				for(int i = 0;i < flist.length;i++)
				{
					compress(out,flist[i],base + "/" + flist[i].getName());
				}
			}
		}else
		// 如果不是目录（文件夹），即为文件，则先写入目录进入点，之后将文件写入zip文件中
		{
			FileInputStream fos = new FileInputStream(sourceFile);
			out.putNextEntry(new ZipEntry(base));
			int tag;
			// 将源文件写入到zip文件中
			while((tag = fos.read()) != -1)
			{
				out.write(tag);
			}
			fos.close();
		}
	}

	private String Get_app_frame()
	{
		String strResult = "";
		StringBuilder strSql = new StringBuilder();
		strSql.append("select * from app_frame where MAIN_ID = '"
				+ this.param_value1 + "'");
		Db_Common_Self dbc_ic = new Db_Common_Self();
		ResultSet rs = null;
		try
		{
			rs = dbc_ic.Common_Sql(strSql);
			while(rs.next())
			{
				strResult = Com_Fun.NoNull(rs.getString("S_DESC"));
				break;
			}
		}
		catch(Exception e)
		{
			Com_Fun.debug_in(e,this.toString(),strSql.toString());
		}
		finally
		{
			try
			{
				if(rs != null)
				{
					rs.getStatement().close();
					rs.close();
				}
			}
			catch(SQLException e)
			{
			}
		}
		return strResult;
	}

	public StringBuilder getStrResult()
	{
		return strResult;
	}

	public void setStrResult(StringBuilder strResult)
	{
		this.strResult = strResult;
	}

	public String getUser_main_id()
	{
		return user_main_id;
	}

	public void setUser_main_id(String user_main_id)
	{
		this.user_main_id = user_main_id;
	}

	public String getSession_id()
	{
		return session_id;
	}

	public void setSession_id(String session_id)
	{
		this.session_id = session_id;
	}

	public String getParam_name()
	{
		return param_name;
	}

	public void setParam_name(String param_name)
	{
		this.param_name = param_name;
	}

	public String getParam_value1()
	{
		return param_value1;
	}

	public void setParam_value1(String param_value1)
	{
		this.param_value1 = param_value1;
	}

	public String getParam_value2()
	{
		return param_value2;
	}

	public void setParam_value2(String param_value2)
	{
		this.param_value2 = param_value2;
	}

	public String getParam_value3()
	{
		return param_value3;
	}

	public void setParam_value3(String param_value3)
	{
		this.param_value3 = param_value3;
	}

	public String getParam_value4()
	{
		return param_value4;
	}

	public void setParam_value4(String param_value4)
	{
		this.param_value4 = param_value4;
	}

	public String getParam_value5()
	{
		return param_value5;
	}

	public void setParam_value5(String param_value5)
	{
		this.param_value5 = param_value5;
	}

	public String getParam_value6()
	{
		return param_value6;
	}

	public void setParam_value6(String param_value6)
	{
		this.param_value6 = param_value6;
	}

	public String getParam_value7()
	{
		return param_value7;
	}

	public void setParam_value7(String param_value7)
	{
		this.param_value7 = param_value7;
	}

	public String getParam_value8()
	{
		return param_value8;
	}

	public void setParam_value8(String param_value8)
	{
		this.param_value8 = param_value8;
	}
}